package com.utils;

import org.testng.*;
import org.testng.xml.XmlSuite;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class MyIReporter implements IReporter {
    @Override
    public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> ISuite, String s) {
        LogCustom logCustom = new LogCustom(this.getClass().getSuperclass());
        List<ITestResult> list = new ArrayList<ITestResult>();
        for (ISuite suite : ISuite) {
            Map<String, ISuiteResult> suiteResults = suite.getResults();
            for (ISuiteResult suiteResult : suiteResults.values()) {
                ITestContext testContext = suiteResult.getTestContext();
                IResultMap passedTests = testContext.getPassedTests();
                IResultMap failedTests = testContext.getFailedTests();
                IResultMap skippedTests = testContext.getSkippedTests();
                IResultMap failedConfig = testContext.getFailedConfigurations();
                list.addAll(this.listTestResult(passedTests));
                list.addAll(this.listTestResult(failedTests));
                list.addAll(this.listTestResult(skippedTests));
//                list.addAll(this.listTestResult(failedConfig));
            }
        }
        for (ITestResult it : list) {
            switch (it.getStatus()) {
                case 1:
                case 2:
                case 3:
                    Object[] aa = it.getParameters();
                    logCustom.info(aa.toString());
                    break;
            }

        }
        TestNG testNG = new TestNG();
    }

    private ArrayList<ITestResult> listTestResult(IResultMap resultMap) {
        Set<ITestResult> results = resultMap.getAllResults();
        return new ArrayList<ITestResult>(results);
    }

}
